// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './vuex/store'
import axios from 'axios'

// 初始化
import './assets/css/reset.css'
import './assets/css/common.css'
import './assets/css/swiper.css'
import './assets/css/vux.css'
import './assets/css/form.css'
import './assets/css/media.css'

// import './assets/js/weixin'

import {hex_sha1} from "./assets/js/sha1"
window.hex_sha1=hex_sha1

// 全局方法
import _g from './assets/js/globalFunctions'
window._g=_g

window._store=store
window.$axios=axios

// window.PATH="/api/"
// window.PATH="/car_doctor/"
// window.backPath="http://192.168.10.113:7070/" //回调地址
// window.backPath="http://www.inbole.com/" 

window.PATH=window.location.href.indexOf("http://192.168.10.113")>-1?"/api/":"/car_doctor/"
window.backPath=window.location.href.indexOf("http://192.168.10.113")>-1?"http://192.168.10.113:7070/":"http://www.inbole.com/"

window.bus=new Vue()

Vue.config.productionTip = false

// 获取百度图像识别授权
import {getWords,wxToken,wxSign,wxUserInfo,getCode,wxConfig} from "./assets/js/getToken"
window.getWords=getWords
window.wxUserInfo=wxUserInfo
window.getCode=getCode


Vue.prototype.axios= axios

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})



router.beforeEach((to, from, next) => {
  // if(to.path.indexOf("/member/voucher/detail/")>-1&&!from.path.indexOf("/member/voucher/detail/")>-1){
  //   window.location.href=backPath+to.path.slice(1)
  // }
  
  if(to.path.indexOf("/work")>-1&&sessionStorage.getItem("isUser")!=0){
    router.replace(from.path)
  }
  next()
})

// 判断ios还是android
Vue.prototype.isIosOrAndroid = function () {
  let u = navigator.userAgent;
  let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 // android终端
  let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios终端
  let isStr = ''
  if (isAndroid) {
    isStr = 'android'
  }
  if (isiOS) {
    isStr = 'ios'
  }
  return isStr
}
window.isIosOrAndroid = function () {
  let u = navigator.userAgent;
  let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 // android终端
  let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios终端
  let isStr = ''
  if (isAndroid) {
    isStr = 'android'
  }
  if (isiOS) {
    isStr = 'ios'
  }
  return isStr
}

router.afterEach((to,from)=>{
  store.state.titleInfo.routerArray.forEach((ele,index)=>{
    if(ele==to.path){
      _g.changeTitle(store.state.titleInfo.titleArray[index])
    }else if(to.path.indexOf("/member/voucher/shareInfo/")>-1){
      _g.changeTitle("领券中心")
    }
  })
  
  store.state.path=to.path
  store.state.dialogs.alert.show=false
  store.state.dialogs.prizealert.show=false
  store.state.dialogs.join.show=false
  store.state.dialogs.charge.show=false
  store.state.dialogs.sure.show=false
  store.state.dialogs.loading.show=false
  store.state.dialogs.reportalert.show=false
  store.state.dialogs.feedback.show=false
})

// var outSettime=null
// var outCount=0
// window.addEventListener("popstate", function(event) {
  // if(outSettime)clearTimeout(outSettime)
  // outCount++
  // if(outCount>1){
  //   if (confirm("确认退出")){
  //     wx.closeWindow();
  //   }
  // }
  // outSettime=setTimeout(()=>{
  //   outCount=0
  // },1000)
// });

var count=0
if(location.href.indexOf("/login?id=")>-1&&count==0){
  count++
  wxUserInfo()
}


// 测试用常量
window.TESTHERE=window.location.href.indexOf("http://192.168.10.113")>-1?true:false
window.TESTUSER=window.location.href.indexOf("http://192.168.10.113")>-1?true:false
if(window.location.href.indexOf("http://192.168.10.113")>-1)_g.login()
// window.TESTHERE=true //本地调用登录
// _g.login()
// window.TESTUSER=true // 测试工作台